package com.cldz.service;

import com.cldz.common.dto.req.DevControlDto;
import com.cldz.common.dto.res.DeviceControlResDto;
import com.cldz.dao.DevControlMapper;
import com.cldz.entity.DeviceControl;
import com.cldz.utils.BeanCopyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ Author     ：lixiao.
 * @ Date       ：Created in 14:46 2018/12/17
 * @ Description：
 * @ Modified By：
 */
@Service("devContolService")
public class DevContolService {

    @Autowired
    private DevControlMapper devControlMapper;


    public List<DeviceControlResDto> getControlRecordByDeviceID(DevControlDto devControlDto){
        List<DeviceControl> controlRecordByDeviceID = devControlMapper.getControlRecordByDeviceID(devControlDto);
        return copyListBean(controlRecordByDeviceID);
    }

    public Integer getControlRecordAmountByDeviceID(DevControlDto devControlDto){

        return devControlMapper.getControlRecordAmountByDeviceID(devControlDto);
    }

    public List<DeviceControlResDto> getAllControlRecord(DevControlDto devControlDto){
        List<DeviceControl> controlRecordByDeviceID = devControlMapper.getAllControlRecord(devControlDto);
        return copyListBean(controlRecordByDeviceID);
    }

    public Integer getAllControlRecordAmount(DevControlDto devControlDto){
        return devControlMapper.getAllControlRecordAmount(devControlDto);
    }

    private List<DeviceControlResDto> copyListBean(List<DeviceControl> devListByTypeID) {
        List<DeviceControlResDto> list = new ArrayList<>();
        for (DeviceControl device : devListByTypeID) {
            DeviceControlResDto dto = new DeviceControlResDto();
            BeanCopyUtil.copyPropertiesIgnoreNull(device, dto);
//            BeanUtils.copyProperties(device, dto);
            list.add(dto);
        }
        return list;
    }

}
